<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":-1,"unescape":false,"preload":true},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"./public/search.xml"};
  </script>

  <meta name="description" content="动态轮播图小米样式">
<meta property="og:type" content="article">
<meta property="og:title" content="动态轮播图">
<meta property="og:url" content="http://yoursite.com/2020/07/14/%E5%8A%A8%E6%80%81%E8%BD%AE%E6%92%AD%E5%9B%BE/index.html">
<meta property="og:site_name" content="GipBaby270&#39;s Blog">
<meta property="og:description" content="动态轮播图小米样式">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2020/07/14/huVH76eNWmgz4n5.png">
<meta property="og:image" content="https://i.loli.net/2020/07/14/g8WioGHt1ncZDj9.png">
<meta property="og:image" content="https://i.loli.net/2020/07/14/uMg9wt6LJQZekKC.png">
<meta property="article:published_time" content="2020-07-14T09:33:27.351Z">
<meta property="article:modified_time" content="2020-07-14T14:09:47.784Z">
<meta property="article:author" content="Gip886">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2020/07/14/huVH76eNWmgz4n5.png">

<link rel="canonical" href="http://yoursite.com/2020/07/14/%E5%8A%A8%E6%80%81%E8%BD%AE%E6%92%AD%E5%9B%BE/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>动态轮播图 | GipBaby270's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    
    <a href="https://github.com/Gip886" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#64CEAA; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">GipBaby270's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Fighting for BAT!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/14/%E5%8A%A8%E6%80%81%E8%BD%AE%E6%92%AD%E5%9B%BE/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/%E5%A4%B4%E5%83%8F.jpg">
      <meta itemprop="name" content="Gip886">
      <meta itemprop="description" content="为了更美好的明天而战">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="GipBaby270's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          动态轮播图
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-07-14 17:33:27 / 修改时间：22:09:47" itemprop="dateCreated datePublished" datetime="2020-07-14T17:33:27+08:00">2020-07-14</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/HTML%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">HTML基础</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="动态轮播图"><a href="#动态轮播图" class="headerlink" title="动态轮播图"></a>动态轮播图</h1><h2 id="小米样式"><a href="#小米样式" class="headerlink" title="小米样式"></a>小米样式</h2><p><img src="https://i.loli.net/2020/07/14/huVH76eNWmgz4n5.png" alt><a id="more"></a></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset&#x3D;&quot;utf-8&quot;&gt;</span><br><span class="line">		&lt;title&gt;&lt;&#x2F;title&gt;</span><br><span class="line">		&lt;style type&#x3D;&quot;text&#x2F;css&quot;&gt;</span><br><span class="line">			*&#123;</span><br><span class="line">				padding: 0;</span><br><span class="line">				margin: 0;</span><br><span class="line">			&#125;</span><br><span class="line">			.imglist img&#123;</span><br><span class="line">				width: 1226px;</span><br><span class="line">				height: 460px;</span><br><span class="line">				position: absolute;</span><br><span class="line">				opacity: 0;</span><br><span class="line">				transition: all 0.5s; </span><br><span class="line">			&#125;</span><br><span class="line">			.imglist .active &#123;</span><br><span class="line">				opacity: 1;</span><br><span class="line">			&#125;</span><br><span class="line">			.container&#123;</span><br><span class="line">				width: 1226px;</span><br><span class="line">				height: 460px;</span><br><span class="line">				margin: 0 auto;</span><br><span class="line">				position: relative;</span><br><span class="line">			&#125;</span><br><span class="line">			.pre&#123;</span><br><span class="line">				width: 40px;</span><br><span class="line">				height: 60px;</span><br><span class="line">				line-height: 60px;</span><br><span class="line">				text-align: center;</span><br><span class="line">				background-color: rgba(0,0,0,0.6);</span><br><span class="line">				color: #fff;</span><br><span class="line">				</span><br><span class="line">				position: absolute;</span><br><span class="line">				font-size: 36px;</span><br><span class="line">				&#x2F;* 上下居中 *&#x2F;</span><br><span class="line">				top: calc(50% - 30px);</span><br><span class="line">			&#125;</span><br><span class="line">			.next&#123;</span><br><span class="line">				width: 40px;</span><br><span class="line">				height: 60px;</span><br><span class="line">				line-height: 60px;</span><br><span class="line">				text-align: center;</span><br><span class="line">				background-color: rgba(0,0,0,0.6);</span><br><span class="line">				color: #fff;</span><br><span class="line">				</span><br><span class="line">				position: absolute;</span><br><span class="line">				font-size: 36px;</span><br><span class="line">				&#x2F;* 上下居中 *&#x2F;</span><br><span class="line">				top: calc(50% - 30px);</span><br><span class="line">				right: 0;</span><br><span class="line">			&#125;</span><br><span class="line">		&lt;&#x2F;style&gt;</span><br><span class="line">	&lt;&#x2F;head&gt;</span><br><span class="line">	&lt;body&gt;</span><br><span class="line">		&lt;div class&#x3D;&quot;container&quot;&gt;</span><br><span class="line">			&lt;div class&#x3D;&quot;imglist&quot;&gt;</span><br><span class="line">			&lt;img src&#x3D;&quot;img&#x2F;img1.jpg&quot; alt&#x3D;&quot;&quot; class&#x3D;&quot;active&quot;&gt;</span><br><span class="line">			&lt;img src&#x3D;&quot;img&#x2F;img2.jpg&quot; alt&#x3D;&quot;&quot; &gt;</span><br><span class="line">			&lt;img src&#x3D;&quot;img&#x2F;img3.jpg&quot; alt&#x3D;&quot;&quot; &gt;</span><br><span class="line">			&lt;img src&#x3D;&quot;img&#x2F;img4.jpg&quot; alt&#x3D;&quot;&quot; &gt;</span><br><span class="line">			&lt;img src&#x3D;&quot;img&#x2F;img5.jpg&quot; alt&#x3D;&quot;&quot; &gt;</span><br><span class="line">			&lt;&#x2F;div&gt;</span><br><span class="line">			</span><br><span class="line">			&lt;div class&#x3D;&quot;btnlist&quot;&gt;</span><br><span class="line">				&lt;div class&#x3D;&quot;pre&quot;&gt; &lt; &lt;&#x2F;div&gt;</span><br><span class="line">				&lt;div class&#x3D;&quot;next&quot;&gt; &gt; &lt;&#x2F;div&gt;	</span><br><span class="line">			&lt;&#x2F;div&gt;</span><br><span class="line">		&lt;&#x2F;div&gt;</span><br><span class="line">	&lt;&#x2F;body&gt;</span><br><span class="line">	&lt;script type&#x3D;&quot;text&#x2F;javascript&quot;&gt;</span><br><span class="line">		var pre &#x3D; document.querySelector(&quot;.pre&quot;);</span><br><span class="line">		var next &#x3D; document.querySelector(&quot;.next&quot;);</span><br><span class="line">		var imgs &#x3D; document.querySelectorAll(&quot;img&quot;);</span><br><span class="line">		var index&#x3D;0;</span><br><span class="line">		next.onclick &#x3D; function()&#123;</span><br><span class="line">			index++;</span><br><span class="line">			if(index&gt;&#x3D;imgs.length)&#123;</span><br><span class="line">				index&#x3D;0;</span><br><span class="line">			&#125;</span><br><span class="line">			imgs.forEach(function(item,i)&#123;</span><br><span class="line">				item.classList.remove(&quot;active&quot;);</span><br><span class="line">			&#125;</span><br><span class="line">			);</span><br><span class="line">			imgs[index].classList.add(&quot;active&quot;);</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">		</span><br><span class="line">		pre.onclick &#x3D; function()&#123;</span><br><span class="line">			index--</span><br><span class="line">			if(index&lt;0)&#123;</span><br><span class="line">				index&#x3D;imgs.length-1</span><br><span class="line">			&#125;</span><br><span class="line">			imgs.forEach(function(item,i)&#123;</span><br><span class="line">				item.classList.remove(&quot;active&quot;)</span><br><span class="line">			&#125;)</span><br><span class="line">			imgs[index].classList.add(&quot;active&quot;)</span><br><span class="line">			</span><br><span class="line">		&#125;</span><br><span class="line">	&lt;&#x2F;script&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure>

<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><ul>
<li><p>calc() 函数用于动态计算长度值。</p>
<ul>
<li>需要注意的是，运算符前后都需要保留一个空格，例如：<code>width: calc(100% - 10px)</code>；</li>
<li>任何长度值都可以使用calc()函数进行计算；</li>
<li>calc()函数支持 “+”, “-“, “*”, “/“ 运算；</li>
<li>calc()函数使用标准的数学运算优先级规则；</li>
</ul>
<p>支持版本：CSS3</p>
<p>文中使用<code>top: calc(50% - 30px);</code>做到上下居中</p>
</li>
<li><p>js编写逻辑（if函数做溢出判断）</p>
</li>
<li><p>过渡<code>transition: all 0.5s;</code> </p>
</li>
<li><p>事件对象自带方法 <strong>for each</strong></p>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">imgs.forEach(function(item,i)&#123;</span><br><span class="line">				item.classList.remove(&quot;active&quot;);</span><br><span class="line">			&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>给元素加类名</p>
<p><strong>方法一：</strong></p>
<p>使用DOM.setAttribute(“class”,”类名”)</p>
<p><strong>方法二：</strong></p>
<p>DOM.classList.add(“类名”)</p>
<p>方法一给DOM元素添加类名会覆盖原有的类名</p>
<p>方法二 可以给DOM元素添加一个类名后 还可以在继续给DOM元素添加新的类名 并且不会覆盖已有的类名</p>
</li>
</ul>
<h2 id="升级样式"><a href="#升级样式" class="headerlink" title="升级样式"></a>升级样式</h2><p><strong>增加下标</strong></p>
<p><img src="https://i.loli.net/2020/07/14/g8WioGHt1ncZDj9.png" alt></p>
<p>原理同上，设置css样式，用flex模型即可，这里提下！</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">*&#123;</span><br><span class="line">				padding: 0;</span><br><span class="line">				margin: 0;</span><br><span class="line">				box-sizing: border-box;</span><br><span class="line">			&#125;</span><br></pre></td></tr></table></figure>

<p><code>box-sizing: border-box</code></p>
<ul>
<li><p>设置了这个属性之后才可以修改flex模型的布局，margin，padding，对里面元素的效果才有有效</p>
</li>
<li><p>box-sizing 最主要的用法是规定容器元素的最终尺寸计算方式。</p>
</li>
</ul>
<p>如果你创造了一个 <div> 没有设置 box-sizing 属性为 border-box(不设置的话默认值为 content-box.)，同时你设置 <strong>width:100px; border:10px solid red; padding:10px;</strong> 那么最终 div 容器的实际宽度为：</div></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">100px(width)+2*10px*(padding)+2*10px(border)&#x3D;140px</span><br></pre></td></tr></table></figure>

<p>所以你会得到一个比你预期（100px）还要更大的容器，结果就是会破坏网页布局。</p>
<p><strong>注意</strong>：容易 margin 的尺寸不会被计算入最终容器宽度，因为对他的定义为对这个容器的留白，但不属于容器本身。</p>
<p>如果当我们定义一个容器的 box-sizing 属性为 border-box 时（表达式：<strong>br{box-sizing:border-box}</strong>），那么我们创建一个和上段中相同设置的 <div> 容器时，那么他的最终宽度即为 100px, 那么它的内容部分（content）的有效宽度变成了 <strong>100px-2*10px-2*10px =60px;</strong> 所以你会得到一个你预期大小的盒子容器，但是只是被压缩了内容部分尺寸而已，但是对于整体布局而言益处颇多。</div></p>
<p>所以要合理利用好这个属性，这个属性十分重要。</p>
<p><a href="https://www.runoob.com/cssref/css3-pr-box-sizing.html" target="_blank" rel="noopener">菜鸟原文链接</a></p>
<ul>
<li>完整代码</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset&#x3D;&quot;utf-8&quot;&gt;</span><br><span class="line">		&lt;title&gt;&lt;&#x2F;title&gt;</span><br><span class="line">		&lt;style type&#x3D;&quot;text&#x2F;css&quot;&gt;</span><br><span class="line">			* &#123;</span><br><span class="line">				padding: 0;</span><br><span class="line">				margin: 0;</span><br><span class="line">				box-sizing: border-box;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.imglist img &#123;</span><br><span class="line">				width: 1226px;</span><br><span class="line">				height: 460px;</span><br><span class="line">				position: absolute;</span><br><span class="line">				opacity: 0;</span><br><span class="line">				transition: all 0.5s;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.imglist .active &#123;</span><br><span class="line">				opacity: 1;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.container &#123;</span><br><span class="line">				width: 1226px;</span><br><span class="line">				height: 460px;</span><br><span class="line">				margin: 0 auto;</span><br><span class="line">				position: relative;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.pre &#123;</span><br><span class="line">				width: 40px;</span><br><span class="line">				height: 60px;</span><br><span class="line">				line-height: 60px;</span><br><span class="line">				text-align: center;</span><br><span class="line">				background-color: rgba(0, 0, 0, 0.6);</span><br><span class="line">				color: #fff;</span><br><span class="line"></span><br><span class="line">				position: absolute;</span><br><span class="line">				font-size: 36px;</span><br><span class="line">				&#x2F;* 上下居中 *&#x2F;</span><br><span class="line">				top: calc(50% - 30px);</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.next &#123;</span><br><span class="line">				width: 40px;</span><br><span class="line">				height: 60px;</span><br><span class="line">				line-height: 60px;</span><br><span class="line">				text-align: center;</span><br><span class="line">				background-color: rgba(0, 0, 0, 0.6);</span><br><span class="line">				color: #fff;</span><br><span class="line"></span><br><span class="line">				position: absolute;</span><br><span class="line">				font-size: 36px;</span><br><span class="line">				&#x2F;* 上下居中 *&#x2F;</span><br><span class="line">				top: calc(50% - 30px);</span><br><span class="line">				right: 0;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.container .circlelist &#123;</span><br><span class="line">				width: 100%;</span><br><span class="line">				height: 60px;</span><br><span class="line">				display: flex;</span><br><span class="line">				justify-content: flex-end;</span><br><span class="line">				align-items: center;</span><br><span class="line">				position: absolute;</span><br><span class="line">				left: 0;</span><br><span class="line">				bottom: 0;</span><br><span class="line">				padding: 0 30px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.container .circlelist .circle &#123;</span><br><span class="line">				width: 10px;</span><br><span class="line">				height: 10px;</span><br><span class="line">				border: 2px solid #999;</span><br><span class="line">				background-color: #666;</span><br><span class="line">				border-radius: 10px;</span><br><span class="line">				margin: 0 5px;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			.container .circlelist .circle.active &#123;</span><br><span class="line">				background-color: #ccc;</span><br><span class="line">				border: 2px solid #666;</span><br><span class="line">			&#125;</span><br><span class="line">		&lt;&#x2F;style&gt;</span><br><span class="line">	&lt;&#x2F;head&gt;</span><br><span class="line">	&lt;body&gt;</span><br><span class="line">		&lt;div class&#x3D;&quot;container&quot;&gt;</span><br><span class="line">			&lt;div class&#x3D;&quot;imglist&quot;&gt;</span><br><span class="line">				&lt;img src&#x3D;&quot;img&#x2F;img1.jpg&quot; alt&#x3D;&quot;&quot; class&#x3D;&quot;active&quot;&gt;</span><br><span class="line">				&lt;img src&#x3D;&quot;img&#x2F;img2.jpg&quot; alt&#x3D;&quot;&quot;&gt;</span><br><span class="line">				&lt;img src&#x3D;&quot;img&#x2F;img3.jpg&quot; alt&#x3D;&quot;&quot;&gt;</span><br><span class="line">				&lt;img src&#x3D;&quot;img&#x2F;img4.jpg&quot; alt&#x3D;&quot;&quot;&gt;</span><br><span class="line">				&lt;img src&#x3D;&quot;img&#x2F;img5.jpg&quot; alt&#x3D;&quot;&quot;&gt;</span><br><span class="line">			&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">			&lt;div class&#x3D;&quot;btnlist&quot;&gt;</span><br><span class="line">				&lt;div class&#x3D;&quot;pre&quot;&gt;</span><br><span class="line">					&lt; &lt;&#x2F;div&gt; &lt;div class&#x3D;&quot;next&quot;&gt; &gt;</span><br><span class="line">				&lt;&#x2F;div&gt;</span><br><span class="line">			&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">			&lt;div class&#x3D;&quot;circlelist&quot;&gt;</span><br><span class="line">				&lt;div id&#x3D;&quot;c0&quot; class&#x3D;&quot;circle active&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">				&lt;div id&#x3D;&quot;c1&quot; class&#x3D;&quot;circle&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">				&lt;div id&#x3D;&quot;c2&quot; class&#x3D;&quot;circle&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">				&lt;div id&#x3D;&quot;c3&quot; class&#x3D;&quot;circle&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">				&lt;div id&#x3D;&quot;c4&quot; class&#x3D;&quot;circle&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line"></span><br><span class="line">			&lt;&#x2F;div&gt;</span><br><span class="line">		&lt;&#x2F;div&gt;</span><br><span class="line">	&lt;&#x2F;body&gt;</span><br><span class="line">	&lt;script type&#x3D;&quot;text&#x2F;javascript&quot;&gt;</span><br><span class="line">		var pre &#x3D; document.querySelector(&quot;.pre&quot;);</span><br><span class="line">		var next &#x3D; document.querySelector(&quot;.next&quot;);</span><br><span class="line">		var imgs &#x3D; document.querySelectorAll(&quot;img&quot;);</span><br><span class="line">		var circlelists &#x3D; document.querySelectorAll(&quot;.circle&quot;);</span><br><span class="line">		var index &#x3D; 0;</span><br><span class="line">		next.onclick &#x3D; function() &#123;</span><br><span class="line">			index++;</span><br><span class="line">			if (index &gt;&#x3D; imgs.length) &#123;</span><br><span class="line">				index &#x3D; 0;</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			resnum();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		pre.onclick &#x3D; function() &#123;</span><br><span class="line">			index--</span><br><span class="line">			if (index &lt; 0) &#123;</span><br><span class="line">				index &#x3D; imgs.length - 1</span><br><span class="line">			&#125;</span><br><span class="line"></span><br><span class="line">			resnum();</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		&#x2F;&#x2F;封装</span><br><span class="line">		function resnum() &#123;</span><br><span class="line">			imgs.forEach(function(item, i) &#123;</span><br><span class="line">				item.classList.remove(&quot;active&quot;);</span><br><span class="line">			&#125;);</span><br><span class="line">			imgs[index].classList.add(&quot;active&quot;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			circlelists.forEach(function(item, i) &#123;</span><br><span class="line">				item.classList.remove(&quot;active&quot;);</span><br><span class="line">			&#125;);</span><br><span class="line">			circlelists[index].classList.add(&quot;active&quot;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">			circlelists.forEach(function(item, i) &#123;</span><br><span class="line">				item.onclick &#x3D; function() &#123;</span><br><span class="line">					&#x2F;&#x2F;字符串和数组一样，索引值拿东西</span><br><span class="line">					num &#x3D; item.id[1];</span><br><span class="line">					index &#x3D; num;</span><br><span class="line">					resnum();</span><br><span class="line">				&#125;</span><br><span class="line">			&#125;);</span><br><span class="line">		&#125;</span><br><span class="line">	&lt;&#x2F;script&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><p><code>num = item.id[1];</code>字符串和数组一样，用索引值拿对应字符，（好用）</p>
</li>
<li><p>当代码复用的时候可以封装成一个函数</p>
</li>
<li><p>这下标样式不错，好看，以后多写这种<img src="https://i.loli.net/2020/07/14/uMg9wt6LJQZekKC.png" alt></p>
</li>
</ul>

    </div>

    
    
    
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续分享！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="Gip886 微信支付">
        <p>微信支付</p>
      </div>

  </div>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/14/%E6%94%BE%E5%A4%A7%E9%95%9C%E6%95%88%E6%9E%9C/" rel="prev" title="放大镜效果">
      <i class="fa fa-chevron-left"></i> 放大镜效果
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/16/node%E4%BB%A3%E7%A0%81%E6%8F%90%E7%A4%BA/" rel="next" title="node代码提示">
      node代码提示 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#动态轮播图"><span class="nav-number">1.</span> <span class="nav-text">动态轮播图</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#小米样式"><span class="nav-number">1.1.</span> <span class="nav-text">小米样式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">1.2.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#升级样式"><span class="nav-number">1.3.</span> <span class="nav-text">升级样式</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Gip886"
      src="/images/%E5%A4%B4%E5%83%8F.jpg">
  <p class="site-author-name" itemprop="name">Gip886</p>
  <div class="site-description" itemprop="description">为了更美好的明天而战</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">29</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Gip886" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Gip886" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=300 height=86 src="//music.163.com/outchain/player?type=2&id=492390949&auto=1&height=66"></iframe>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Gip886</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">153k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">2:19</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>


  




  
<script src="/js/local-search.js"></script>













  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false,"tagMode":false});</script></body>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/clicklove.js"></script>
</html>

